package com.ce.utils;

import java.security.MessageDigest;
import java.util.UUID;

import android.util.Log;

public class StringUtils {

	public static String getMD5Str(String str) {
		MessageDigest messageDigest = null;
		try{
			messageDigest = MessageDigest.getInstance("MD5");
			messageDigest.reset();
			messageDigest.update(str.getBytes("UTF-8"));
		}catch (Exception e) {
			Log.d(StringUtils.class.getName(), "MD5 error!", e);
		}
		byte[] byteArray = messageDigest.digest();
		StringBuffer sb = new StringBuffer();
		for(int i = 0 ; i < byteArray.length; i++) {
			if(Integer.toHexString(0xFF & byteArray[i]).length() == 1) 
				sb.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
			else
				sb.append(Integer.toHexString(0xFF & byteArray[i]));
		}
		return sb.substring(8,24).toString().toUpperCase();
	}
	
	public static boolean isNullOrEmpty(String str) {
		if(str == null)
			return true;
		if("".equals(str.trim()))
			return true;
		return false;
	}
	
	public static String getGUID() {
		return UUID.randomUUID().toString();
	}
}
